// 我的
const app = getApp();
import { PACKAGE_OWNER_PAGE, COMMON_PAGE } from '../../constants/route';
import { USER_EXT_INFO_SCENE } from '../../constants/user';
import { getUserExtInfo } from '../../api/usr';
import { getUserInfo, getUserToken } from '../../biztools/wex';
import { UserInfoUpdateMixins, UserAuthInfoEditMixins } from '../../behaviors/page';
import { showLoading, hideLoading, copyText, tipSuccess } from '../../common/env';
import { getConfig } from '../../api/common';
import { IS_DEV } from '../../config';

const { navTo } = require('../../common/env')
Page({
    mixins: [UserInfoUpdateMixins, UserAuthInfoEditMixins],
    data: {
        userInfo: getUserInfo(),
        userExtInfo: {},
        router: PACKAGE_OWNER_PAGE,
        userConfig: {},
        IS_DEV,
    },
    onShow: async function () {
        const config = await getConfig();
        this.setData({
            userConfig: config,
        });
        if (!app.globalData.isReadyAuth) {
            const _ = this;
            const originFunc = app.userIdentifyCallback;
            app.userIdentifyCallback = function (...args) {
                _.onShow(...args);
                return originFunc && originFunc(...args);
            }
            return;
        } else {
            showLoading('加载中...');
            // 获取用户额外信息
            const userExtInfo = await getUserExtInfo(USER_EXT_INFO_SCENE.owner);
            console.log('Owner => 获取到的用户额外信息为：', userExtInfo);
            this.setData({
                userExtInfo,
            });
            hideLoading();
        }
    },
    bindMobileSuccess() {
        this.setData({
            userInfo: getUserInfo(),
        });
    },
    gotoExpandActivityList: function () {
        const { userExtInfo } = this.data;
        navTo(PACKAGE_OWNER_PAGE.ownerActivity, {
            expandCount: (userExtInfo.endorseBrandCount || 0) + (userExtInfo.endorseStoreCount || 0),
        });
    },
    // 打开客服
    openService: function () {
        
    },
    // 打开关于
    openAbout: function () {
        navTo(COMMON_PAGE.webview, {
            url: this.data.userConfig.aboutUrl,
        });
    },
    copyToken() {
        copyText(getUserToken(), () => {
            tipSuccess('复制了token');
        });
    },
})